package com.jack.thinking.java._22.swing.progress;

import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.JSlider;
import javax.swing.ProgressMonitor;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import com.utils.SwingConsole;

/**
 * 进度条 (展示了两种 方式， 一种是共享模型， 一种是 通过监听器)
 * @author wangbingwu
 *
 */
public class Progress extends JFrame{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JProgressBar pb = new JProgressBar();
	private ProgressMonitor pm = new ProgressMonitor(this, "Monitor Progresss", "Test", 0, 100);
	private JSlider sb = new JSlider(JSlider.HORIZONTAL, 0, 100, 60);
	
	public Progress() {
		setLayout(new GridLayout(2, 1));
		add(pb);
		pm.setProgress(0);
		pm.setMillisToPopup(1000);
		sb.setValue(0);
		sb.setPaintTicks(true);           // 是否留下刻痕
		sb.setMajorTickSpacing(20);		  // 主刻度间距
		sb.setMinorTickSpacing(5);		  // 副
		sb.setBorder(new TitledBorder("Slide Me"));
		pb.setModel(sb.getModel());
		add(sb);
		sb.addChangeListener(new ChangeListener() {
			
			@Override
			public void stateChanged(ChangeEvent e) {
				pm.setProgress(sb.getValue());
			}
		});
		
	}
	
	public static void main(String[] args) {
		SwingConsole.run(new Progress(), 300, 200);
	}
}
